﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using ScrumTable.Common;
using ScrumTable.DL.Data.Common.Config.Driver;
using ScrumTable.DL.Data.Common.Config.Schema;

#endregion

namespace ScrumTable.DL.Data.Common
{
    /// <summary>
    /// Contains additional information for a data driver which is required
    /// to initialize the driver and its environment.
    /// </summary>
    public class DataContextInfo : IDataContextInfo
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private readonly IDataAssemblyInfo _assemblyInfo;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the selected source for the schema configuration.
        /// </summary>
        public IDataSchemaSource ConfiguredSchemaSource { get; private set; }

        /// <summary>
        /// Gets the selected source for the driver configuration.
        /// </summary>
        public IDriverConfigSource ConfiguredDriverConfigSource { get; private set; }

        /// <summary>
        /// Gets the description of the data assembly. This property may be
        /// used in a UI drop down list in order to select a proprietary
        /// data connector plug in.
        /// </summary>
        public string Description { get { return _assemblyInfo.Description; } }

        /// <summary>
        /// Gets the user specific configuration folder path for the current application.
        /// </summary>
        public string ConfigFolderPath { get { return _assemblyInfo.ConfigFolderPath; } }

        /// <summary>
        /// Gets the user specific data folder path for the current application.
        /// </summary>
        public string DataFolderPath { get { return _assemblyInfo.DataFolderPath; } }

        /// <summary>
        /// Returns true if the data assembly reqiures strong username / password authentication.
        /// </summary>
        public bool AssemblyRequiresStrongAuthentication { get { return _assemblyInfo.AssemblyRequiresStrongAuthentication; } }

        /// <summary>
        /// Specifies the data assembly format for the driver data source link (passed to the Connect()).
        /// </summary>
        public DataSourceLinkFormat AssemblyRequiredLinkFormat { get { return _assemblyInfo.AssemblyRequiredLinkFormat; } }

        /// <summary>
        /// Gets the schema data sources associated to the current data assembly and
        /// its data driver.
        /// </summary>
        /// <remarks>Hide this property because its references should not be used in the
        /// underlying data driver code. The reference and data inside this objects may be
        /// changed through the GUI which may result in an unexpceted behaviour.</remarks>
        IDataSchemaSelector IDataAssemblyInfo.DataSchemaSelector { get { return _assemblyInfo.DataSchemaSelector; } }

        /// <summary>
        /// Gets the configuration data sources associated to the current data assembly and
        /// its data driver.
        /// </summary>
        /// <remarks>Hide this property because its references should not be used in the
        /// underlying data driver code. The reference and data inside this objects may be
        /// changed through the GUI which may result in an unexpceted behaviour.</remarks>
        IDriverConfigSelector IDataAssemblyInfo.DriverConfigSelector { get { return _assemblyInfo.DriverConfigSelector; } }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates the initialization information object for a new IDataContext
        /// instance.
        /// </summary>
        public DataContextInfo(IDataAssemblyInfo assemblyInfo)
        {
            PreCondition.AssertNotNull(assemblyInfo, "assemblyInfo");
            
            _assemblyInfo = assemblyInfo;

            ConfiguredSchemaSource = _assemblyInfo.DataSchemaSelector.Selected;
            ConfiguredDriverConfigSource = _assemblyInfo.DriverConfigSelector.Selected;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Maps a file path to a file which is stored on the underlying 
        /// hard drive in conjunction with the data file-system data retrieval rules.
        /// </summary>
        /// <param name="fileToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapDataFilePath(string fileToMap)
        {
            return _assemblyInfo.MapDataFilePath(fileToMap);
        }

        /// <summary>
        /// Maps a folder path to a file which is stored on the underlying 
        /// hard drive in conjunction with the data driver file-system data retrieval rules.
        /// </summary>
        /// <param name="folderToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapDataFolderPath(string folderToMap)
        {
            return _assemblyInfo.MapDataFolderPath(folderToMap);
        }

        /// <summary>
        /// Maps a file path to a file which is stored on the underlying 
        /// hard drive in conjunction with the config file-system data retrieval rules.
        /// </summary>
        /// <param name="fileToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapConfigFilePath(string fileToMap)
        {
            return _assemblyInfo.MapConfigFilePath(fileToMap);
        }

        /// <summary>
        /// Maps a folder path to a file which is stored on the underlying 
        /// hard drive in conjunction with the config driver file-system data retrieval rules.
        /// </summary>
        /// <param name="folderToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapConfigFolderPath(string folderToMap)
        {
            return _assemblyInfo.MapConfigFolderPath(folderToMap);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}